package com.example.springboot_demo01.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;


/**
 * Swagger的配置类
 */
@Configuration
@EnableSwagger2WebMvc//http://127.0.0.1:8081/doc.html#/home
public class SwaggerConfig {
    //测试API
    @Bean
    public Docket myDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("测试")
                .apiInfo(myApiInfo())//调用的api描述方法
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.springboot_demo01"))//扫描的API包路径
                .build();
    }

    public ApiInfo myApiInfo() {
        return new ApiInfoBuilder()
                .title("测试API文档")
                .version("1.0")
                .build();
    }

}